﻿<UserControl x:Class="Passwords.Views.PasswordGenView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vm="clr-namespace:Passwords.ViewModels"
             xmlns:controls="clr-namespace:Passwords.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="476" d:DesignWidth="501">
    <UserControl.InputBindings>
        <KeyBinding Key="Esc" Command="{x:Static vm:Commands.ClosePasswordGen}" CommandParameter="false"/>
        <KeyBinding Key="Enter" Command="{x:Static vm:Commands.ClosePasswordGen}" CommandParameter="true"/>
        <KeyBinding Key="G"  Modifiers="Ctrl" Command="{x:Static vm:Commands.GeneratePassword}" />
    </UserControl.InputBindings>
    <UserControl.Resources>
        <ExponentialEase Exponent="5" EasingMode="EaseOut" x:Key="ease"/>
        <BackEase x:Key="backEase" EasingMode="EaseOut"/>
        <ControlTemplate TargetType="UserControl" x:Key="template">
            <Grid x:Name="grid" Background="#80808080"  DataContext="{Binding PasswordGen}" >
                <Border x:Name="window" Background="{DynamicResource AppBackground}" VerticalAlignment="Center" HorizontalAlignment="Center"  CacheMode="BitmapCache">
                    <StackPanel  Margin="15" >
                        <StackPanel.Resources>
                            <Style TargetType="Button" BasedOn="{StaticResource iconButtonStyle}">
                                <Setter Property="Width" Value="NaN"/>
                                <Setter Property="BorderThickness" Value="2"/>
                                <Setter Property="BorderBrush" Value="{DynamicResource AppForeground}"/>
                                <Setter Property="Foreground" Value="{DynamicResource AppForeground}"/>
                                <Setter Property="Background" Value="Transparent"/>
                                <Setter Property="FontWeight" Value="Bold"/>
                            </Style>
                            <Style TargetType="CheckBox">
                                <Setter Property="TextBlock.FontSize" Value="14"/>
                                <Setter Property="Margin" Value="4,2"/>
                                <Setter Property="Foreground" Value="{DynamicResource AppForeground}"/>
                            </Style>
                        </StackPanel.Resources>
                        <TextBlock Text="{Binding rs.PasswordGeneratorTitle, Source={StaticResource locale}}" FontSize="20" FontWeight="Bold" Margin="4,2,4,8"/>
                        <TextBox x:Name="pws" Text="{Binding Password,  ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, FallbackValue=pws}" 
                                 MinWidth="200" Margin="4,2" MaxWidth="320"/>
                        <CheckBox Content="{Binding rs.IncludeLowerCaseChars, Source={StaticResource locale}}"  IsChecked="{Binding UseLowerCase}"/>
                        <CheckBox Content="{Binding rs.IncludeUpperCaseChars, Source={StaticResource locale}}" IsChecked="{Binding UseUpperCase}"/>
                        <CheckBox Content="{Binding rs.IncludeDigits, Source={StaticResource locale}}" IsChecked="{Binding UseDigits}"/>
                        <CheckBox Content="{Binding rs.IncludeSpecialChars, Source={StaticResource locale}}" IsChecked="{Binding UseSpecial}"/>
                        <StackPanel Orientation="Horizontal">
                            <TextBox x:Name="tb" Text="{Binding NumChars, FallbackValue=10}"  Width="64" Margin="4,2" HorizontalContentAlignment="Right" />
                            <TextBlock Text="{Binding rs.PWGenCharactersText, Source={StaticResource locale}}" VerticalAlignment="Center" Margin="4,2" FontSize="14"/>
                        </StackPanel>
                        <Grid >
                            <TextBlock Text="{Binding rs.PWGenStrengthText, Source={StaticResource locale}}" Margin="4,2"/>
                            <TextBlock Text="{Binding StrengthText, FallbackValue=weak}" Margin="4,2" HorizontalAlignment="Right"/>
                        </Grid>
                        <ProgressBar Margin="4,2" Value="{Binding Strength, FallbackValue=40}" Maximum="140" Height="10" Style="{StaticResource pwsAppProgressBarStyle}"/>
                        <Button Content="{Binding rs.PWGenGenerateBtn, Source={StaticResource locale}}" Margin="4,8" HorizontalAlignment="Stretch" Command="{x:Static vm:Commands.GeneratePassword}" Background="Transparent" />
                        <StackPanel Orientation="Horizontal" Margin="0,8" HorizontalAlignment="Center">
                            <Button Content="{Binding rs.PWGenOk, Source={StaticResource locale}}"  Margin="4,2" Width="100" Command="{x:Static vm:Commands.ClosePasswordGen}" CommandParameter="true" Background="Transparent" />
                            <Button Content="{Binding rs.PWGenCancel, Source={StaticResource locale}}" Margin="4,2" Width="100" Command="{x:Static vm:Commands.ClosePasswordGen}" CommandParameter="false" Background="Transparent" />
                        </StackPanel>
                    </StackPanel>
                    <Border.Effect>
                        <DropShadowEffect BlurRadius="20"/>
                    </Border.Effect>
                    <Border.RenderTransform>
                        <ScaleTransform x:Name="scale" CenterX="200" CenterY="200" />
                    </Border.RenderTransform>
                </Border>
            </Grid>
            <ControlTemplate.Triggers>
                <DataTrigger Binding="{Binding IsPasswordGenVisible}" Value="true">
                    <Setter Property="controls:FocusContainer.IsFocused" Value="true" TargetName="pws" />
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation From="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="grid" Duration="0:0:0.2" EasingFunction="{StaticResource ease}"/>
                                <DoubleAnimation From="0" To="1" Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="scale" Duration="0:0:0.2" EasingFunction="{StaticResource ease}"/>
                                <DoubleAnimation From="0" To="1" Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="scale" Duration="0:0:0.2" EasingFunction="{StaticResource ease}"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </UserControl.Resources>
    <UserControl.Style>
        <Style TargetType="UserControl">
            <Setter Property="Template" Value="{StaticResource template}"/>
            <Setter Property="Visibility" Value="Collapsed"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsPasswordGenVisible}" Value="true">
                    <Setter Property="Visibility" Value="Visible"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Style>
</UserControl>
